package io.renren.modules.ccs.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.ccs.entity.TypeEntity;
import io.renren.modules.ccs.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;



/**
 * 
 *
 * @author SongR
 * @email 348329560@qq.com
 * @date 2018-07-25 16:03:25
 */
@RestController
@RequestMapping("ccs/type")
public class TypeController{
    @Autowired
    private TypeService typeService;

    
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ccs:type:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = typeService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 角色列表
	 */
	@RequestMapping("/select")
	@RequiresPermissions("ccs:type:select")
	public R select(){
		List<TypeEntity> list = typeService.selectList(null);
		return R.ok().put("list", list);
	}
    
    
    /**
     * 信息
     */
    @RequestMapping("/info/{typeId}")
    @RequiresPermissions("ccs:type:info")
    public R info(@PathVariable("typeId") Long typeId){
        TypeEntity type = typeService.selectById(typeId);

        return R.ok().put("type", type);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ccs:type:save")
    public R save(@RequestBody TypeEntity type){
//    	type.setTypeStatus(1);
        typeService.insert(type);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ccs:type:update")
    public R update(@RequestBody TypeEntity type){
        ValidatorUtils.validateEntity(type);
        typeService.updateAllColumnById(type);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ccs:type:delete")
    public R delete(@RequestBody Long[] typeIds){
        typeService.deleteBatchIds(Arrays.asList(typeIds));

        return R.ok();
    }

}
